/*
 *          		  MidiMaker 
 *       		   (Working title)
 *  		Joe Mirizio & Earl Bellinger
 * 
 *	GNU General Public License version 3.0 (GPLv3)
 */
package midimaker;

import javax.sound.midi.*;
import java.util.*;

public class test {
	
	public static void main(String[] args) throws Exception {
        /* CREATE MUSICMAKER AND SEQUENCE */
        MidiPlayer m = new MidiPlayer();
        Sequence s = null;
        try {
        	s = new Sequence(Sequence.PPQ, 1);
        } 
        catch (InvalidMidiDataException e) { 
        	e.printStackTrace(); 
        	System.exit(1); 
        }
        
        /* GENERATE HARMONY */
        int[] harmony = new int[8];
        do
        	for (int i = 0; i < harmony.length - 1; i++)
        		harmony[i] = new Random().nextInt(7);
        while (harmony[harmony.length - 2] == 0 && (harmony[harmony.length-2] == 4 || harmony[harmony.length-2] == 3));
        harmony[0] = 0;
        harmony[harmony.length/2] = 0;
        //harmony[harmony.length - 2] = 4;
        harmony[harmony.length - 1] = 0;
        
        /* CREATE INSTRUMENTS */
        ArrayList<InstrumentTrack> instruments = new ArrayList<InstrumentTrack>();
        //instruments.add(new Piano(s.createTrack(), 0));
        instruments.add(new Guitar(s.createTrack(), 1));
        instruments.add(new Bass(s.createTrack(), 2));
        instruments.add(new Drum(s.createTrack(), 9));
        for (InstrumentTrack it : instruments) {
            int[][] notes = it.generateNotes(harmony);
            it.setNotes(notes);
        }

        /* PLAY SEQUENCE */
        m.playSequence(s);
        /* WRITE SEQUENCE TO FILE */
        m.writeToFile("midi1.mid", s);
    }
}